package ACWing._785快速排序;

import java.io.*;

public class Main {
    static void quicksort(int[] a,int l,int r){
        if(l>=r)
            return;
        int k = part(a, l,r);
        quicksort(a,l,k-1);
        quicksort(a,k+1,r);
    }
    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    // 在l,r之间通过交换找一个位置,使得
    static int part(int[] a,int l,int r){
        int i = l+r>>1;    // base值下标
        int t = a[i];
        swap(a,i,l);

        while (l<r){
            // 找到右边第一个比小的
            while (r>l&&a[r]>=t) r--;
            a[l] = a[r];
            // 左边第一个比t大的
            while (l<r&& a[l]<=t) l++;
            a[r] = a[l];
        }
        a[l] = t;
        return l;
    }


    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(reader.readLine());
        int[] a = new int[n];
        String[] nums =reader.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(nums[i]);
        }
        quicksort(a,0,n-1);
        writer.write(a[0]+"");
        for (int i = 1; i < n; i++) {
            writer.write(" "+a[i]);
        }
        writer.flush();
        reader.close();
        writer.close();

    }
}
